package priv.zgh.forum.re.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.util.StringUtils;
import priv.zgh.forum.re.entity.ResourcesSimulator;
import priv.zgh.forum.re.mapper.ResourcesSimulatorMapper;
import priv.zgh.forum.re.service.ResourcesSimulatorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZGH
 * @since 2022-04-21
 */
@Service
public class ResourcesSimulatorServiceImpl extends ServiceImpl<ResourcesSimulatorMapper, ResourcesSimulator> implements ResourcesSimulatorService {

    @Override
    public Page<ResourcesSimulator> pageResourcesConditionByType(int i, long current, long limit, ResourcesSimulator query) {
        Page<ResourcesSimulator> page = new Page<>(current,limit);
        QueryWrapper<ResourcesSimulator> wrapper = new QueryWrapper<>();
        //取出查询封装的数据
        String resourcesName = query.getResourcesName();
        //拼接动态SQL语句
        if(!StringUtils.isEmpty(resourcesName)){
            //构建条件
            wrapper.like("resources_name",resourcesName);
        }
        //根据创建时间排序
        wrapper.orderByDesc("gmt_create");
        //将条件wrapper封装进service进行查询,然后将放回的结果封装进page
        baseMapper.selectPage(page,wrapper);
        return page;
    }
}
